/*
 * CompressArgumentHandler.h
 *
 *  Created on: 28/05/2011
 *      Author: Agustina I. Stekolschik
 */
#include "CompressArgumentHandler.h"
#include <Logging.h>
#include <sys/stat.h>
#include <CompressionProcess.h>

using logging::Logger;
using logging::LoggerFactory;
using logging::Level;

using namespace providers;


bool FileToCompressExists(string strFilename) {
  struct stat stFileInfo;
  bool blnReturn;
  int intStat;

  intStat = stat(strFilename.c_str(),&stFileInfo);
  if(intStat == 0) {
    blnReturn = true;
  } else {
    blnReturn = false;
  }
  return(blnReturn);
}

CompressArgumentHandler::CompressArgumentHandler(Tag& aTag, std::string& aDescription) : CommandLineProcess::ArgumentHandler(aTag,aDescription){
}

bool CompressArgumentHandler::handleArgument(std::string& argument){
	Logger& logger = LoggerFactory::getInstance().getLogger("ArgumentHandler.Compress");

	if (FileToCompressExists(argument)){
		CompressionProcessProvider::setCompressionCommand("compression");
		CompressionProcessProvider::setCompressionFileRoute(argument.c_str());
	}else{
		logger.log(logging::ERROR, "The given resource does not exist. Check passed arguments.");
		return false;
	}
	return true;
}

CompressArgumentHandler::~CompressArgumentHandler(){
}
